unit ubalcao;

interface

uses
  Windows, variants, Messages, clipbrd, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, Grids, DBGrids, ComCtrls, Db, DBTables, StdCtrls, DBCtrls, Mask,
  Buttons, ToolWin, ActnList, Menus;

type

THackDBGrid = class(TDBGrid);

  Tfbalcao = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    ScrollBox1: TScrollBox;
    Panel1: TPanel;
    ScrollBox2: TScrollBox;
    Panel21: TPanel;
    Panel11: TPanel;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Label6: TLabel;
    Label3: TLabel;
    EditQtd: TDBEdit;
    EditSubtotal: TDBEdit;
    EditPreco: TDBEdit;
    GroupBox2: TGroupBox;
    Label10: TLabel;
    Label11: TLabel;
    Label5: TLabel;
    EditTotal: TDBEdit;
    EditRecebido: TDBEdit;
    EditTroco: TDBEdit;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    Label4: TLabel;
    DBText1: TDBText;
    DBEdit1: TDBEdit;
    GroupBox4: TGroupBox;
    SpeedButton1: TSpeedButton;
    Panel14: TPanel;
    DBGrid3: TDBGrid;
    Panel9: TPanel;
    Panel3: TPanel;
    tbpedido: TTable;
    dspedido: TDataSource;
    tbitem: TTable;
    dsitem: TDataSource;
    ActionList1: TActionList;
    Totalizar: TAction;
    preencher: TAction;
    Excluir: TAction;
    campos: TAction;
    novo: TAction;
    foco: TAction;
    estoque: TAction;
    formatar: TAction;
    fimageitem: TAction;
    conta: TAction;
    novoitem: TAction;
    Timer1: TTimer;
    Panel5: TPanel;
    Timer2: TTimer;
    StatusBar1: TStatusBar;
    DBText2: TDBText;
    DBGrid1: TDBGrid;
    Panel24: TPanel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    SpeedButton4: TSpeedButton;
    MaskEdit1: TMaskEdit;
    MaskEdit2: TMaskEdit;
    SpeedButton5: TSpeedButton;
    Panel23: TPanel;
    DBGrid2: TDBGrid;
    Label12: TLabel;
    Panel22: TPanel;
    imprimir: TAction;
    confirmar: TAction;
    btngravar: TSpeedButton;
    SpeedButton3: TSpeedButton;
    ajuda: TAction;
    deleteitem: TAction;
    ComboBox1: TComboBox;
    Label13: TLabel;
    Edit1: TEdit;
    Image1: TImage;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btngravarClick(Sender: TObject);
    procedure TotalizarExecute(Sender: TObject);
    procedure preencherExecute(Sender: TObject);
    procedure tbitemNewRecord(DataSet: TDataSet);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure DBRadioGroup1Exit(Sender: TObject);
    procedure ExcluirExecute(Sender: TObject);
    procedure camposExecute(Sender: TObject);
    procedure focoExecute(Sender: TObject);
    procedure novoExecute(Sender: TObject);
    procedure estoqueExecute(Sender: TObject);
    procedure formatarExecute(Sender: TObject);
    procedure EditRecebidoExit(Sender: TObject);
    procedure EditPrecoExit(Sender: TObject);
    procedure contaExecute(Sender: TObject);
    procedure tbitemAfterScroll(DataSet: TDataSet);
    procedure DBEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure novoitemExecute(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure tbitemBeforeEdit(DataSet: TDataSet);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure MaskEdit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure PageControl1Change(Sender: TObject);
    procedure MaskEdit2Change(Sender: TObject);
    procedure MaskEdit1Change(Sender: TObject);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure DBEdit1Exit(Sender: TObject);
    procedure EditQtdExit(Sender: TObject);
    procedure imprimirExecute(Sender: TObject);
    procedure confirmarExecute(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure ajudaExecute(Sender: TObject);
    procedure deleteitemExecute(Sender: TObject);
    procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ComboBox1Change(Sender: TObject);
  private
   procedure AppHint(Sender : TObject);
    { Private declarations }
  public
  BOK : boolean;
  St, tipo, CAIXA : String;
  it:integer;
    { Public declarations }
  end;

var
  fbalcao: Tfbalcao;

implementation

uses UnitDadoEmpresa, Extens, UnitMenu, ulistaproduto, UnitRelatorio, UNota, udm;




procedure tfbalcao.AppHint(Sender: TObject);
begin
  StatusBar1.Panels[0].Text := Application.Hint;
end;

{$R *.DFM}

procedure Tfbalcao.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
	        Application.OnHint := nil;
end;

procedure Tfbalcao.btngravarClick(Sender: TObject);
begin
        confirmarexecute(self);
end;

procedure Tfbalcao.TotalizarExecute(Sender: TObject);
var
tot1, tot2, tot3, tot4 : real;
bookmark : tbookmarkstr;
begin


     tbitem.edit;
     tbitem['total'] := (tbitem.fieldbyname ('vrunit') as tfloatfield).Value * (tbitem.fieldbyname ('qtd') as tfloatfield).Value;

     bookmark := tbitem.Bookmark;

     try

      tbitem.DisableControls;
      tot1 := 0;
      tot2 := 0;
      tot3 := 0;
      tot4 := 0;

    try
    tbitem.First;

    while not tbitem.Eof do begin

    if tbitem['total'] <> null then
    tot1 := tot1 + (tbitem.fieldbyname ('total') as tfloatfield).Value;

    if tbitem['icm'] <> null then
    tot2 := tot2 + (tbitem.fieldbyname ('icm') as tfloatfield).Value;

    if tbitem['comissao'] <> null then
    tot3 := tot3 + (tbitem.fieldbyname ('comissao') as tfloatfield).Value;

    if tbitem['ipi'] <> null then
    tot4 := tot4 + (tbitem.fieldbyname ('ipi') as tfloatfield).Value;

    tbitem.next;
    end;
    finally

    tbitem.EnableControls;
    end;
    finally
    tbitem.Bookmark := bookmark;
    end;

    tbpedido.edit;

    tbpedido['total'] := tot1;
    tbpedido['vricm'] := tot1 / 100 * tot2;
    tbpedido['vrcomissao'] := tot1 / 100 * tot3;
    tbpedido['vripi'] := tot1 / 100 * tot4;
    tbpedido['vendedor'] := combobox1.Text;

    if editrecebido.text <>'' then
    tbpedido['troco'] := (tbpedido.fieldbyname ('recebido') as tfloatfield).Value - (tbpedido.fieldbyname ('total') as tfloatfield).Value;



end;

procedure Tfbalcao.preencherExecute(Sender: TObject);
var
prod, prod1 : string;

begin
      fdm.tbproduto.open;
       if fdm.tbproduto.Locate('codigo',tbitem['codigo'],[]) then begin

        if fdm.tbproduto['produto'] <> null then prod := fdm.tbproduto['produto'];
         if fdm.tbproduto['descricao'] <> null then prod := prod + ' ' + fdm.tbproduto['descricao'];

        tbitem.edit;
         tbitem['nome'] := prod;
          tbitem['vrunit'] := fdm.tbproduto['vrvenda'];
            tbitem['un'] := fdm.tbproduto['un'];
             tbitem['codigobarra'] := fdm.tbproduto['codigobarra'];

             if tbitem['nome']<> null then
              prod1 := tbitem['nome'];

              if fdm.tbproduto['vrvenda'] <> null then
               prod1 := prod1 + ' - R$ ' +  format('%n',[(tbitem.fieldbyname ('vrunit') as tfloatfield).Value]);


              panel21.caption := prod1 ;
               timer1.Enabled := false;
                timer2.Enabled := false;

           end else
         showmessage('Produto não foi cadastrado, ou campo código em branco, verificar!!!');

            fdm.tbproduto.close;
             panel22.Caption :='';

end;

procedure Tfbalcao.tbitemNewRecord(DataSet: TDataSet);
begin
        tbitem['pedido'] := tbpedido['pedido'];
        tbitem['operacao'] := tbpedido['operacao'];
        tbitem['data'] := tbpedido['data'];
        tbitem['fantasia'] := tbpedido['fantasia'];
        tbitem['icm'] := fdadoempresa.SpinEdit1.Value;
        tbitem['ipi'] := fdadoempresa.SpinEdit1.Value;
        tbitem['comissao'] := strtofloat(edit1.Text) ;
        tbitem['vendedor'] := combobox1.Text;
end;

procedure Tfbalcao.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if key=#13 then begin
  Key := #0;
       Perform(WM_nextdlgctl,0,0)
 end else if Key = #27 then
   Perform(WM_nextdlgctl,1,0);
end;

procedure Tfbalcao.DBRadioGroup1Exit(Sender: TObject);
begin

      tbitem.DisableControls;

    tbitem.First;

    while not tbitem.Eof do begin
    tbitem.edit;
    tbitem['operacao'] := tbpedido['operacao'];
    tbitem.post;
    tbitem.next;
    end;

    tbitem.EnableControls;


end;

procedure Tfbalcao.ExcluirExecute(Sender: TObject);
 var
 doc:string;

begin

        doc := tbpedido['pedido'];

        fdm.tbreceber.Filter:='docparcela = ''' + doc +'''';
         fdm.tbreceber.Filtered := true;

       fdm.tbreceber.Last;

       while fdm.tbreceber['docparcela'] <> null do begin
        fdm.tbreceber.delete;
         fdm.tbreceber.next;
           end;

        fdm.tbreceber.Filtered := false;
end;

procedure Tfbalcao.camposExecute(Sender: TObject);
begin
        fdm.tbreceber.insert;
        fdm.tbreceber['venc1'] := 'À VISTA';
        fdm.tbreceber['dataemissao'] := tbpedido['data'];
        fdm.tbreceber['docparcela'] := tbpedido['pedido'];
        fdm.tbreceber['fantasia'] :='BALCÃO';
        fdm.tbreceber['numeropedido'] := tbpedido['pedido'];
        fdm.tbreceber['valortitulo'] := tbpedido['total'];
        fdm.tbreceber['valordocumento'] := tbpedido['total'];
        fdm.tbreceber['VrDesconto'] := tbpedido['total'];
        fdm.tbreceber['extenso']:=Extens.Extenso(tbpedido['total']);
        fdm.tbreceber['vendedor'] := tbpedido['vendedor'];
        fdm.tbreceber['vrcomissao'] := tbpedido['vrcomissao'];
        fdm.tbreceber.post;

end;

procedure Tfbalcao.focoExecute(Sender: TObject);
begin
        it := it + 1;

        if it = 3 then it:=1;

        case it of

        1: dbedit1.setfocus;
        2: dbgrid3.setfocus;
        end;

end;

procedure Tfbalcao.novoExecute(Sender: TObject);
begin

        btnGravar.Enabled:=true;
       tbpedido.Refresh;

        with fdm.query1 do begin
         close;
          sql.clear;
           sql.add('select max(pedido) as codigo from tbpedido');
            open;
         end;

        tbpedido.insert;
        if fdm.query1['codigo'] <> null then
         tbpedido['pedido'] := fdm.query1['codigo'] + 1
        else
        tbpedido['pedido']:='1';
        tbpedido['operacao']:='P';
        tbpedido['data']:=DateTostr(now);
        tbpedido['fantasia']:='BALCAO';

        st := '';

          fdm.query1.close;

end;

procedure Tfbalcao.estoqueExecute(Sender: TObject);
var
tot, tot1: real;

begin

        with fdm.Query1 do begin
         close;
          sql.clear;
           sql.add ('select codigo, nome, sum(qtd)as entrada from tbentradaitem');
            sql.add (' where codigo = "'+ dbedit1.text + '" group by codigo, nome');
            open;
        end;

        with fdm.Query2 do begin
         close;
          sql.clear;
           sql.add ('select codigo, nome, sum(qtd) as saida from tbpedidoitem');
            sql.add (' where operacao="P" and codigo = "'+ dbedit1.text + '" group by codigo, nome');
            open;
        end;

        fdm.tbproduto.Open;


        if fdm.tbproduto.Locate('codigo',fdm.query1['codigo'],[]) then
        tot1:= fdm.tbproduto.FieldByName('minimo').asfloat
        else
        tot1 := 0;

        FDM.tbproduto.close;


        tot := (fdm.query1.fields[2].asfloat - fdm.query2.fields[2].asfloat);

        if fdm.query1['nome'] <> null then
            showmessage('ESTOQUE = ' + floattostr(tot) + ' ' + fdm.query1['nome']+#13+
            'ESTOQUE MÍNIMO = '+ floattostr(tot1))
        else
        showmessage('Estoque Vazio!!!');

             fdm.query1.Close;
              fdm.query2.Close;
end;

procedure Tfbalcao.formatarExecute(Sender: TObject);
begin

 (tbpedido.fieldbyname ('data') as tdatetimefield).editmask := '99/99/9999';
 (tbpedido.fieldbyname ('pedido') as tfloatfield).displayformat := '000000';
 (tbpedido.fieldbyname ('total') as tfloatfield).displayformat := '###,##0.00';
 (tbpedido.fieldbyname ('recebido') as tfloatfield).displayformat := '###,##0.00';
 (tbpedido.fieldbyname ('troco') as tfloatfield).displayformat := '###,##0.00';

 (tbitem.fieldbyname ('codigo') as tfloatfield).displayformat := '000000';
 (tbitem.fieldbyname ('vrunit') as tfloatfield).displayformat := '###,##0.00';
 (tbitem.fieldbyname ('total') as tfloatfield).displayformat := '###,##0.00';
 (tbitem.fieldbyname ('qtd') as tfloatfield).displayformat := '00';

end;

procedure Tfbalcao.EditRecebidoExit(Sender: TObject);
begin
        tbpedido.Edit;
            if editrecebido.text <>'' then
         tbpedido['troco'] := (tbpedido.fieldbyname ('recebido') as tfloatfield).Value - (tbpedido.fieldbyname ('total') as tfloatfield).Value;
end;

procedure Tfbalcao.EditPrecoExit(Sender: TObject);
begin
        totalizarexecute(self);
end;

procedure Tfbalcao.contaExecute(Sender: TObject);
begin
    if tbpedido['total']= null then begin
    showmessage('Não há valor para esta venda, verificar!!!');
    abort;
    end;


     fdm.tbreceber.open;

     if fdm.tbreceber.Locate ('docparcela',tbpedido['pedido'],[]) then
      excluirexecute(self);
       camposexecute(self);

      fdm.tbreceber.close;

end;

procedure Tfbalcao.tbitemAfterScroll(DataSet: TDataSet);
   var
   pt:string;
begin

    fdm.tbproduto.open;

     fdm.tbproduto.Locate('codigo',tbitem['codigo'],[]);
      if fdm.tbproduto['imagem'] <> null then begin
       pt := fdm.tbproduto['imagem'] ;
       if fileexists (pt) then
        image1.Picture.LoadFromFile (pt);
        end else
      image1.Picture.LoadFromFile(extractfilepath(paramstr(0)) + '\imagem\imagem.wmf');
      fdm.tbproduto.close;

end;

procedure Tfbalcao.DBEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

        if key = vk_F12 then begin
         timer1.Enabled := false;
          Application.CreateForm (Tflistaproduto, flistaproduto);
           flistaproduto.st :='balcao';
            flistaproduto.table1.open;
             flistaproduto.showmodal;
              end;

       if key = vk_F5 then
        estoqueexecute(self);

end;

procedure Tfbalcao.novoitemExecute(Sender: TObject);
begin
       dbedit1.SetFocus;
        tbitem.Insert;

      btngravar.Enabled := true;
      panel21.caption := '';

end;

procedure Tfbalcao.SpeedButton1Click(Sender: TObject);
begin
        novoitemexecute(self);
end;

procedure Tfbalcao.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin

        fdm.tbfatura.close;
        fdm.tbproduto.Close;

        tbpedido.Last;

         if dbedit1.Text <> '' then begin
         tbpedido.edit;
          tbpedido.post;
           tbitem.edit;
            tbitem.post;


              if edittotal.Text <> '0,00' then begin
              contaexecute(self);
              end else
              Showmessage('Não há total para esta venda, verificar.');

       end else

          tbpedido.delete;

end;

procedure Tfbalcao.tbitemBeforeEdit(DataSet: TDataSet);
begin
       btnGravar.Enabled:=True;
end;

procedure Tfbalcao.FormActivate(Sender: TObject);
begin
        THackDBGrid(DBGrid3).FixedCols := 5;

        with fdm.Query1 do begin
         close;
          sql.clear;
           sql.add ('select apel from tbvendedor order by apel');
            open;
             end;

        combobox1.Items.Clear;

        fdm.Query1.First;

        while not fdm.Query1.Eof do begin

         if fdm.Query1['apel'] <> null then
         combobox1.Items.Add(fdm.Query1['apel']);

         fdm.Query1.Next;

        end;

        fdm.Query1.Close;

        if pagecontrol1.ActivePageIndex = 0 then
         combobox1.setfocus;


end;

procedure Tfbalcao.FormCreate(Sender: TObject);
begin
       Application.OnHint := AppHint;
       Timer1Timer(self);
       Timer2Timer(self);
end;

procedure Tfbalcao.Timer2Timer(Sender: TObject);
   var
   pt,prod:string;
begin

    fdm.tbproduto.open;

    fdm.tbproduto.next;

     if fdm.tbproduto.Eof then
      fdm.tbproduto.first;


      if fdm.tbproduto['imagem'] <> null then begin
       pt := fdm.tbproduto['imagem'] ;
        if fileexists (pt) then
        image1.Picture.LoadFromFile (pt);
         end else
          image1.Picture.LoadFromFile(extractfilepath(paramstr(0)) + '\imagem\imagem.wmf');


        if fdm.tbproduto['produto'] <> null then prod := fdm.tbproduto['produto'];
         if fdm.tbproduto['descricao'] <> null then prod := prod + ' ' + fdm.tbproduto['descricao'];
          if fdm.tbproduto['vrvenda'] <> null then prod := prod + ' - R$ ' +  format('%n',[(fdm.tbproduto.fieldbyname ('vrvenda') as tfloatfield).Value]);

          panel22.Caption := prod;

end;

procedure Tfbalcao.MaskEdit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

        if key = 13 then begin
        tbpedido.Filtered := false;
        if (maskedit1.text <>'  /  /    ') and (maskedit2.text <>'  /  /    ') then
        tbpedido.filter := 'data >=''' + maskedit1.text + ''' and data<=''' +  maskedit2.text + '''';
        tbpedido.filtered := true;
        end;
end;

procedure Tfbalcao.PageControl1Change(Sender: TObject);
begin

        tbpedido.Filtered := false;

        if PageControl1.ActivePageIndex = 0 then begin

              if edittotal.Text <> '0,00' then begin
              contaexecute(self);
              end else
              Showmessage('Não há total para esta venda, verificar.');


        tbpedido.Last;

        if tbitem['codigo']= null then begin
        Panel21.caption := ' - BALCÃO - CAIXA LIVRE ';
        timer1.Enabled := true;
        timer2.Enabled := true;
        end;

        end else begin

        maskedit1.SetFocus;
        timer1.Enabled := false;
        timer2.Enabled := false;
        tbpedido.Filtered := false;
        THackDBGrid(DBGrid2).FixedCols := 8;

        end;



end;

procedure Tfbalcao.MaskEdit2Change(Sender: TObject);
begin
       if maskedit2.Text = '  /  /    ' then
        maskedit2.Clear;
end;

procedure Tfbalcao.MaskEdit1Change(Sender: TObject);
begin
       if maskedit1.Text = '  /  /    ' then
        maskedit1.Clear;
end;

procedure Tfbalcao.DBGrid1DblClick(Sender: TObject);
Var
 vendaini, vendafin:String;
begin


     if InputQuery ('filtrar...', 'Entre com o número inicial da venda',vendaini ) then

      if InputQuery ('filtrar...', 'Entre com o número final da venda',vendafin ) then begin
       tbpedido.filter := 'pedido >= ''' + vendaini + ''' and pedido<= ''' + vendafin +'''' ;
        tbpedido.filtered := true;
         end;


end;

procedure Tfbalcao.SpeedButton4Click(Sender: TObject);
begin
        maskedit1.Clear;
        maskedit2.Clear;
        tbpedido.filtered := false;
end;

procedure Tfbalcao.SpeedButton5Click(Sender: TObject);
var
tot : real;
bookmark : tbookmarkstr;
begin

      bookmark :=  tbpedido.Bookmark;
      tbpedido.DisableControls;
      tot := 0;

    try
    tbpedido.First;

    while not tbpedido.Eof do begin

    tot := tot + (tbpedido.fieldbyname ('total') as tfloatfield).Value;
    tbpedido.next;
    end;
    finally

    tbpedido.EnableControls;

    end;

    tbpedido.Bookmark := bookmark;

    st := format('%n', [tot]);

    application.MessageBox(pchar('Total : R$ ' + st), 'Soma das vendas do período determinado',mb_ok + MB_ICONWARNING)



end;

procedure Tfbalcao.Timer1Timer(Sender: TObject);
var
texto:string;

begin

  Texto := panel21.Caption ;
  panel21.Caption := Copy(Texto,2,Length(Texto))+Texto[1];


end;

procedure Tfbalcao.DBEdit1Exit(Sender: TObject);
begin
         preencherexecute(self);
          totalizarexecute(self);

end;

procedure Tfbalcao.EditQtdExit(Sender: TObject);
begin
          totalizarexecute(self);
end;

procedure Tfbalcao.imprimirExecute(Sender: TObject);
var
bookmark : tbookmarkstr;

begin

///////////////////////////
      bookmark := tbpedido.Bookmark;

      tbpedido.Filter := 'pedido = ''' + floattostr(tbpedido['pedido']) + '''';
       tbpedido.Filtered := true;

        Application.CreateForm(Tfrpedido, frpedido);

  fmenu.logotipoExecute(self);
  if fileexists (extractfilepath(paramstr(0)) + '\imagem\dado.txt') then
   FrPedido.memo4.lines.loadfromfile(extractfilepath(paramstr(0)) + '\imagem\dado.txt');


          frpedido.quickvenda.Print;
           frpedido.Release;
            tbpedido.Filtered := false;

          tbpedido.Bookmark := bookmark;


end;

procedure Tfbalcao.confirmarExecute(Sender: TObject);
begin
      if edittotal.Text <> '0,00' then begin
        tbpedido.edit;
         tbpedido.post;
          tbitem.edit;
           tbitem.Post;


          if Application.MessageBox('Imprimir comprovante de venda? ',
          'Impressão', 4 + MB_ICONQUESTION)= idYes then
            imprimirexecute(self);

           contaexecute(self);
            novoexecute (self);
             Panel21.caption := ' - BALCÃO - CAIXA LIVRE ';
              timer1.Enabled := true;
               timer2.Enabled := true;
                dbedit1.SetFocus;

      end else

      Showmessage('Não há total para esta venda, verificar.');

end;

procedure Tfbalcao.SpeedButton3Click(Sender: TObject);
begin
        imprimirexecute(self);
end;

procedure Tfbalcao.ajudaExecute(Sender: TObject);
var
  Comp: Trichedit; // * variável Comp da classe TMemo
  texto : string;
begin
  Comp := Trichedit.Create (Self);  // * cria o componente Memo
  Comp.Parent := Self;    // * exibe o componente criado

  if fileexists (extractfilepath(paramstr(0)) + '\ajuda\ajudabalcao.txt') then
   comp.lines.loadfromfile (extractfilepath(paramstr(0)) + '\ajuda\ajudabalcao.txt');

  texto := comp.Text;
  comp.Destroy;

  Showmessage (texto);


end;

procedure Tfbalcao.deleteitemExecute(Sender: TObject);
begin

        if application.MessageBox('Apagar o ítem selecionado?','Excluir',4 + MB_ICONWARNING ) = mryes then begin
         tbitem.Delete;
          totalizarexecute(self);
           end;
end;

procedure Tfbalcao.ComboBox1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = 13 then pagecontrol1.SetFocus;
end;

procedure Tfbalcao.ComboBox1Change(Sender: TObject);
begin
        fdm.tbvendedor.Open;

        if fdm.tbvendedor.Locate('apel', ComboBox1.Text, []) then
         edit1.Text := floattostr(fdm.tbvendedor['comissao']);

          fdm.tbvendedor.Close;


       tbitem.DisableControls;

       tbitem.First;

       while not tbitem.Eof do begin

        tbitem.edit;

        tbitem['comissao'] := strtofloat(edit1.Text) ;
        tbitem['vendedor'] := combobox1.Text;

      tbitem.Next;
      end;

      tbitem.EnableControls;

      totalizarexecute(self);




end;

end.



